
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>1.2. 概念与原则 · MobX 中文文档</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../refguide/api.html" />
    
    
    <link rel="prev" href="overview.html" />
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"buttons":[{"user":"SangKa","repo":"MobX-Docs-CN","type":"star","size":"small","count":true},{"user":"SangKa","repo":"MobX-Docs-CN","type":"fork","size":"small","count":true}]};
    </script>

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    1. MobX 介绍
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.1" data-path="overview.html">
            
                <a href="overview.html">
            
                    
                    1.1. MobX 要点
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.1.2" data-path="concepts.html">
            
                <a href="concepts.html">
            
                    
                    1.2. 概念与原则
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../refguide/api.html">
            
                <a href="../refguide/api.html">
            
                    
                    2. API概览
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    3. observable 相关
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../refguide/observable.html">
            
                <a href="../refguide/observable.html">
            
                    
                    3.1. observable
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../refguide/observable-decorator.html">
            
                <a href="../refguide/observable-decorator.html">
            
                    
                    3.2. @observable
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../refguide/object.html">
            
                <a href="../refguide/object.html">
            
                    
                    3.3. objects
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../refguide/array.html">
            
                <a href="../refguide/array.html">
            
                    
                    3.4. arrays
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../refguide/map.html">
            
                <a href="../refguide/map.html">
            
                    
                    3.5. maps
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../refguide/boxed.html">
            
                <a href="../refguide/boxed.html">
            
                    
                    3.6. boxed values
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="../refguide/modifiers.html">
            
                <a href="../refguide/modifiers.html">
            
                    
                    3.7 decorators
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    4. 对 observables 作出响应
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../refguide/computed-decorator.html">
            
                <a href="../refguide/computed-decorator.html">
            
                    
                    4.1. (@)computed
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../refguide/autorun.html">
            
                <a href="../refguide/autorun.html">
            
                    
                    4.2. autorun
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../refguide/when.html">
            
                <a href="../refguide/when.html">
            
                    
                    4.3. when
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../refguide/reaction.html">
            
                <a href="../refguide/reaction.html">
            
                    
                    4.4. reaction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../refguide/observer-component.html">
            
                <a href="../refguide/observer-component.html">
            
                    
                    4.5. (@)observer
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../best/react.html">
            
                <a href="../best/react.html">
            
                    
                    4.6. 理解 MobX 对何作出响应
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    5. 改变 observables
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../refguide/action.html">
            
                <a href="../refguide/action.html">
            
                    
                    5.1. action
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../best/actions.html">
            
                <a href="../best/actions.html">
            
                    
                    5.2. async actions & flows
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../refguide/object-api.html">
            
                <a href="../refguide/object-api.html">
            
                    
                    5.3. Object api
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" >
            
                <span>
            
                    
                    6. 工具函数
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../refguide/tojson.html">
            
                <a href="../refguide/tojson.html">
            
                    
                    6.1. toJS
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../refguide/extend-observable.html">
            
                <a href="../refguide/extend-observable.html">
            
                    
                    6.2. extendObservable
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../refguide/extending.html">
            
                <a href="../refguide/extending.html">
            
                    
                    6.3. createAtom
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../refguide/observe.html">
            
                <a href="../refguide/observe.html">
            
                    
                    6.4. intercept & observe
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" >
            
                <a target="_blank" href="https://github.com/mobxjs/mobx-utils#frompromise">
            
                    
                    6.5. mobxUtils.fromPromise
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" >
            
                <a target="_blank" href="https://github.com/mobxjs/mobx-utils#fromresource">
            
                    
                    6.6. mobxUtils.fromResource
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" >
            
                <a target="_blank" href="https://github.com/mobxjs/mobx-utils#tostream">
            
                    
                    6.7. mobxUtils.toStream
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" >
            
                <a target="_blank" href="https://github.com/mobxjs/mobx-utils#fromstream">
            
                    
                    6.8. mobxUtils.fromStream
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" >
            
                <a target="_blank" href="https://github.com/mobxjs/mobx-utils#now">
            
                    
                    6.9. mobxUtils.now
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../refguide/create-transformer.html">
            
                <a href="../refguide/create-transformer.html">
            
                    
                    6.10. mobxUtils.createTransformer
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.11" data-path="../refguide/expr.html">
            
                <a href="../refguide/expr.html">
            
                    
                    6.11. mobxUtils.expr
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.12" data-path="../refguide/api.html">
            
                <a href="../refguide/api.html">
            
                    
                    6.12. complete api overview
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" >
            
                <a target="_blank" href="https://github.com/mobxjs/awesome-mobx#examples">
            
                    
                    7. 博客、 视频及相关项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" >
            
                <span>
            
                    
                    8. 贴士与技巧
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../faq/faq.html">
            
                <a href="../faq/faq.html">
            
                    
                    8.1. 常见问题解答
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../best/pitfalls.html">
            
                <a href="../best/pitfalls.html">
            
                    
                    8.2. 常见陷阱与最佳实践
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../best/decorators.html">
            
                <a href="../best/decorators.html">
            
                    
                    8.3. 如何(不)使用装饰器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../best/trace.html">
            
                <a href="../best/trace.html">
            
                    
                    8.4. 使用 trace 进行调试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="../best/store.html">
            
                <a href="../best/store.html">
            
                    
                    8.5. 定义数据存储
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="../best/react-performance.html">
            
                <a href="../best/react-performance.html">
            
                    
                    8.6. 优化 React 组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="../best/devtools.html">
            
                <a href="../best/devtools.html">
            
                    
                    8.7. 开发工具
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="../refguide/spy.html">
            
                <a href="../refguide/spy.html">
            
                    
                    8.8. spy
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../donating.html">
            
                <a href="../donating.html">
            
                    
                    9. 捐赠
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >1.2. 概念与原则</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x6982;&#x5FF5;&#x4E0E;&#x539F;&#x5219;"><a name="&#x6982;&#x5FF5;&#x4E0E;&#x539F;&#x5219;" class="plugin-anchor" href="#&#x6982;&#x5FF5;&#x4E0E;&#x539F;&#x5219;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x6982;&#x5FF5;&#x4E0E;&#x539F;&#x5219;</h1>
<h2 id="&#x6982;&#x5FF5;"><a name="&#x6982;&#x5FF5;" class="plugin-anchor" href="#&#x6982;&#x5FF5;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x6982;&#x5FF5;</h2>
<p>MobX &#x533A;&#x5206;&#x4E86;&#x4EE5;&#x4E0B;&#x51E0;&#x4E2A;&#x5E94;&#x7528;&#x4E2D;&#x7684;&#x6982;&#x5FF5;&#x3002; &#x5728;&#x4E4B;&#x524D;&#x7684;&#x8981;&#x70B9;&#x4E2D;&#x5DF2;&#x7ECF;&#x89C1;&#x8FC7;&#x4E86;&#xFF0C;&#x73B0;&#x5728;&#x8BA9;&#x6211;&#x4EEC;&#x66F4;&#x6DF1;&#x5165;&#x5730;&#x4E86;&#x89E3;&#x5B83;&#x4EEC;&#x3002;</p>
<h3 id="1-state&#x72B6;&#x6001;"><a name="1-state&#x72B6;&#x6001;" class="plugin-anchor" href="#1-state&#x72B6;&#x6001;"><i class="fa fa-link" aria-hidden="true"></i></a>1. State(&#x72B6;&#x6001;)</h3>
<p><strong>&#x72B6;&#x6001;</strong> &#x662F;&#x9A71;&#x52A8;&#x5E94;&#x7528;&#x7684;&#x6570;&#x636E;&#x3002;
&#x901A;&#x5E38;&#x6709;&#x50CF;&#x5F85;&#x529E;&#x4E8B;&#x9879;&#x5217;&#x8868;&#x8FD9;&#x6837;&#x7684;<strong>&#x9886;&#x57DF;&#x7279;&#x5B9A;&#x72B6;&#x6001;</strong>&#xFF0C;&#x8FD8;&#x6709;&#x50CF;&#x5F53;&#x524D;&#x5DF2;&#x9009;&#x5143;&#x7D20;&#x7684;<strong>&#x89C6;&#x56FE;&#x72B6;&#x6001;</strong>&#x3002;
&#x8BB0;&#x4F4F;&#xFF0C;&#x72B6;&#x6001;&#x5C31;&#x50CF;&#x662F;&#x6709;&#x6570;&#x636E;&#x7684;excel&#x8868;&#x683C;&#x3002;</p>
<h3 id="2-derivations&#x884D;&#x751F;"><a name="2-derivations&#x884D;&#x751F;" class="plugin-anchor" href="#2-derivations&#x884D;&#x751F;"><i class="fa fa-link" aria-hidden="true"></i></a>2. Derivations(&#x884D;&#x751F;)</h3>
<p><strong>&#x4EFB;&#x4F55;</strong> &#x6E90;&#x81EA;<strong>&#x72B6;&#x6001;</strong>&#x5E76;&#x4E14;&#x4E0D;&#x4F1A;&#x518D;&#x6709;&#x4EFB;&#x4F55;&#x8FDB;&#x4E00;&#x6B65;&#x7684;&#x76F8;&#x4E92;&#x4F5C;&#x7528;&#x7684;&#x4E1C;&#x897F;&#x5C31;&#x662F;&#x884D;&#x751F;&#x3002;
&#x884D;&#x751F;&#x4EE5;&#x591A;&#x79CD;&#x5F62;&#x5F0F;&#x5B58;&#x5728;:</p>
<ul>
<li><strong>&#x7528;&#x6237;&#x754C;&#x9762;</strong></li>
<li><strong>&#x884D;&#x751F;&#x6570;&#x636E;</strong>&#xFF0C;&#x6BD4;&#x5982;&#x5269;&#x4E0B;&#x7684;&#x5F85;&#x529E;&#x4E8B;&#x9879;&#x7684;&#x6570;&#x91CF;&#x3002;</li>
<li><strong>&#x540E;&#x7AEF;&#x96C6;&#x6210;</strong>&#xFF0C;&#x6BD4;&#x5982;&#x628A;&#x53D8;&#x5316;&#x53D1;&#x9001;&#x5230;&#x670D;&#x52A1;&#x5668;&#x7AEF;&#x3002;</li>
</ul>
<p>MobX &#x533A;&#x5206;&#x4E86;&#x4E24;&#x79CD;&#x7C7B;&#x578B;&#x7684;&#x884D;&#x751F;:</p>
<ul>
<li><strong>Computed values(&#x8BA1;&#x7B97;&#x503C;)</strong> - &#x5B83;&#x4EEC;&#x662F;&#x6C38;&#x8FDC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x7EAF;&#x51FD;&#x6570;(pure function)&#x4ECE;&#x5F53;&#x524D;&#x53EF;&#x89C2;&#x5BDF;&#x72B6;&#x6001;&#x4E2D;&#x884D;&#x751F;&#x51FA;&#x7684;&#x503C;&#x3002;</li>
<li><strong>Reactions(&#x53CD;&#x5E94;)</strong> - Reactions &#x662F;&#x5F53;&#x72B6;&#x6001;&#x6539;&#x53D8;&#x65F6;&#x9700;&#x8981;&#x81EA;&#x52A8;&#x53D1;&#x751F;&#x7684;&#x526F;&#x4F5C;&#x7528;&#x3002;&#x9700;&#x8981;&#x6709;&#x4E00;&#x4E2A;&#x6865;&#x6881;&#x6765;&#x8FDE;&#x63A5;&#x547D;&#x4EE4;&#x5F0F;&#x7F16;&#x7A0B;(imperative programming)&#x548C;&#x54CD;&#x5E94;&#x5F0F;&#x7F16;&#x7A0B;(reactive programming)&#x3002;&#x6216;&#x8005;&#x8BF4;&#x5F97;&#x66F4;&#x660E;&#x786E;&#x4E00;&#x4E9B;&#xFF0C;&#x5B83;&#x4EEC;&#x6700;&#x7EC8;&#x90FD;&#x9700;&#x8981;&#x5B9E;&#x73B0;I / O &#x64CD;&#x4F5C;&#x3002;</li>
</ul>
<p>&#x521A;&#x5F00;&#x59CB;&#x4F7F;&#x7528; MobX &#x65F6;&#xFF0C;&#x4EBA;&#x4EEC;&#x503E;&#x5411;&#x4E8E;&#x9891;&#x7E41;&#x7684;&#x4F7F;&#x7528; reactions&#x3002;
&#x9EC4;&#x91D1;&#x6CD5;&#x5219;: &#x5982;&#x679C;&#x4F60;&#x60F3;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x57FA;&#x4E8E;&#x5F53;&#x524D;&#x72B6;&#x6001;&#x7684;&#x503C;&#x65F6;&#xFF0C;&#x8BF7;&#x4F7F;&#x7528; <code>computed</code>&#x3002;</p>
<p>&#x56DE;&#x5230;excel&#x8868;&#x683C;&#x8FD9;&#x4E2A;&#x6BD4;&#x55BB;&#x4E2D;&#x6765;&#xFF0C;&#x516C;&#x5F0F;&#x662F;<strong>&#x8BA1;&#x7B97;</strong>&#x503C;&#x7684;&#x884D;&#x751F;&#x3002;&#x4F46;&#x5BF9;&#x4E8E;&#x7528;&#x6237;&#x6765;&#x8BF4;&#xFF0C;&#x80FD;&#x770B;&#x5230;&#x5C4F;&#x5E55;&#x7ED9;&#x51FA;&#x7684;<strong>&#x53CD;&#x5E94;</strong>&#x5219;&#x9700;&#x8981;&#x90E8;&#x5206;&#x91CD;&#x7ED8;GUI&#x3002;</p>
<h3 id="3-actions&#x52A8;&#x4F5C;"><a name="3-actions&#x52A8;&#x4F5C;" class="plugin-anchor" href="#3-actions&#x52A8;&#x4F5C;"><i class="fa fa-link" aria-hidden="true"></i></a>3. Actions(&#x52A8;&#x4F5C;)</h3>
<p><strong>&#x52A8;&#x4F5C;</strong> &#x662F;&#x4EFB;&#x4E00;&#x4E00;&#x6BB5;&#x53EF;&#x4EE5;&#x6539;&#x53D8;<strong>&#x72B6;&#x6001;</strong>&#x7684;&#x4EE3;&#x7801;&#x3002;&#x7528;&#x6237;&#x4E8B;&#x4EF6;&#x3001;&#x540E;&#x7AEF;&#x6570;&#x636E;&#x63A8;&#x9001;&#x3001;&#x9884;&#x5B9A;&#x4E8B;&#x4EF6;&#x3001;&#x7B49;&#x7B49;&#x3002;
&#x52A8;&#x4F5C;&#x7C7B;&#x4F3C;&#x4E8E;&#x7528;&#x6237;&#x5728;excel&#x5355;&#x5143;&#x683C;&#x4E2D;&#x8F93;&#x5165;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x503C;&#x3002;</p>
<p>&#x5728; MobX &#x4E2D;&#x53EF;&#x4EE5;&#x663E;&#x5F0F;&#x5730;&#x5B9A;&#x4E49;&#x52A8;&#x4F5C;&#xFF0C;&#x5B83;&#x53EF;&#x4EE5;&#x5E2E;&#x4F60;&#x628A;&#x4EE3;&#x7801;&#x7EC4;&#x7EC7;&#x7684;&#x66F4;&#x6E05;&#x6670;&#x3002;
&#x5982;&#x679C;&#x662F;&#x5728;<a href="../refguide/api#-enforceactions"><strong>&#x4E25;&#x683C;&#x6A21;&#x5F0F;</strong></a>&#x4E0B;&#x4F7F;&#x7528; MobX&#x7684;&#x8BDD;&#xFF0C;MobX &#x4F1A;&#x5F3A;&#x5236;&#x53EA;&#x6709;&#x5728;&#x52A8;&#x4F5C;&#x4E4B;&#x4E2D;&#x624D;&#x53EF;&#x4EE5;&#x4FEE;&#x6539;&#x72B6;&#x6001;&#x3002;</p>
<h2 id="&#x539F;&#x5219;"><a name="&#x539F;&#x5219;" class="plugin-anchor" href="#&#x539F;&#x5219;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x539F;&#x5219;</h2>
<p>MobX &#x652F;&#x6301;&#x5355;&#x5411;&#x6570;&#x636E;&#x6D41;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;<strong>&#x52A8;&#x4F5C;</strong>&#x6539;&#x53D8;<strong>&#x72B6;&#x6001;</strong>&#xFF0C;&#x800C;&#x72B6;&#x6001;&#x7684;&#x6539;&#x53D8;&#x4F1A;&#x66F4;&#x65B0;&#x6240;&#x6709;&#x53D7;&#x5F71;&#x54CD;&#x7684;<strong>&#x89C6;&#x56FE;</strong>&#x3002;</p>
<p><img src="../images/action-state-view.png" alt="Action, State, View"></p>
<p>&#x5F53;<strong>&#x72B6;&#x6001;</strong>&#x6539;&#x53D8;&#x65F6;&#xFF0C;&#x6240;&#x6709;<strong>&#x884D;&#x751F;</strong>&#x90FD;&#x4F1A;&#x8FDB;&#x884C;<strong>&#x539F;&#x5B50;&#x7EA7;&#x7684;&#x81EA;&#x52A8;</strong>&#x66F4;&#x65B0;&#x3002;&#x56E0;&#x6B64;&#x6C38;&#x8FDC;&#x4E0D;&#x53EF;&#x80FD;&#x89C2;&#x5BDF;&#x5230;&#x4E2D;&#x95F4;&#x503C;&#x3002;</p>
<p>&#x6240;&#x6709;<strong>&#x884D;&#x751F;</strong>&#x9ED8;&#x8BA4;&#x90FD;&#x662F;<strong>&#x540C;&#x6B65;</strong>&#x66F4;&#x65B0;&#x3002;&#x8FD9;&#x610F;&#x5473;&#x7740;&#x4F8B;&#x5982;<strong>&#x52A8;&#x4F5C;</strong>&#x53EF;&#x4EE5;&#x5728;&#x6539;&#x53D8;<strong>&#x72B6;&#x6001;</strong>&#x4E4B;&#x540E;&#x76F4;&#x63A5;&#x53EF;&#x4EE5;&#x5B89;&#x5168;&#x5730;&#x68C0;&#x67E5;&#x8BA1;&#x7B97;&#x503C;&#x3002;</p>
<p><strong>&#x8BA1;&#x7B97;&#x503C;</strong> &#x662F;<strong>&#x5EF6;&#x8FDF;</strong>&#x66F4;&#x65B0;&#x7684;&#x3002;&#x4EFB;&#x4F55;&#x4E0D;&#x5728;&#x4F7F;&#x7528;&#x72B6;&#x6001;&#x7684;&#x8BA1;&#x7B97;&#x503C;&#x5C06;&#x4E0D;&#x4F1A;&#x66F4;&#x65B0;&#xFF0C;&#x76F4;&#x5230;&#x9700;&#x8981;&#x5B83;&#x8FDB;&#x884C;&#x526F;&#x4F5C;&#x7528;&#xFF08;I / O&#xFF09;&#x64CD;&#x4F5C;&#x65F6;&#x3002;
&#x5982;&#x679C;&#x89C6;&#x56FE;&#x4E0D;&#x518D;&#x4F7F;&#x7528;&#xFF0C;&#x90A3;&#x4E48;&#x5B83;&#x4F1A;&#x81EA;&#x52A8;&#x88AB;&#x5783;&#x573E;&#x56DE;&#x6536;&#x3002;</p>
<p>&#x6240;&#x6709;&#x7684;<strong>&#x8BA1;&#x7B97;&#x503C;</strong>&#x90FD;&#x5E94;&#x8BE5;&#x662F;<strong>&#x7EAF;&#x51C0;</strong>&#x7684;&#x3002;&#x5B83;&#x4EEC;&#x4E0D;&#x5E94;&#x8BE5;&#x7528;&#x6765;&#x6539;&#x53D8;<strong>&#x72B6;&#x6001;</strong>&#x3002;</p>
<h2 id="&#x5B9E;&#x4F8B;"><a name="&#x5B9E;&#x4F8B;" class="plugin-anchor" href="#&#x5B9E;&#x4F8B;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5B9E;&#x4F8B;</h2>
<p>&#x4E0B;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x6E05;&#x5355;&#x4E3E;&#x4F8B;&#x8BF4;&#x660E;&#x4E86;&#x4EE5;&#x4E0A;&#x7684;&#x6982;&#x5FF5;&#x548C;&#x539F;&#x5219;:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> {observable, autorun} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;mobx&apos;</span>;

<span class="hljs-keyword">var</span> todoStore = observable({
    <span class="hljs-comment">/* &#x4E00;&#x4E9B;&#x89C2;&#x5BDF;&#x7684;&#x72B6;&#x6001; */</span>
    todos: [],

    <span class="hljs-comment">/* &#x63A8;&#x5BFC;&#x503C; */</span>
    get completedCount() {
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.todos.filter(todo =&gt; todo.completed).length;
    }
});

<span class="hljs-comment">/* &#x89C2;&#x5BDF;&#x72B6;&#x6001;&#x6539;&#x53D8;&#x7684;&#x51FD;&#x6570; */</span>
autorun(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;Completed %d of %d items&quot;</span>,
        todoStore.completedCount,
        todoStore.todos.length
    );
});

<span class="hljs-comment">/* ..&#x4EE5;&#x53CA;&#x4E00;&#x4E9B;&#x6539;&#x53D8;&#x72B6;&#x6001;&#x7684;&#x52A8;&#x4F5C; */</span>
todoStore.todos[<span class="hljs-number">0</span>] = {
    title: <span class="hljs-string">&quot;Take a walk&quot;</span>,
    completed: <span class="hljs-literal">false</span>
};
<span class="hljs-comment">// -&gt; &#x540C;&#x6B65;&#x6253;&#x5370; &apos;Completed 0 of 1 items&apos;</span>

todoStore.todos[<span class="hljs-number">0</span>].completed = <span class="hljs-literal">true</span>;
<span class="hljs-comment">// -&gt; &#x540C;&#x6B65;&#x6253;&#x5370; &apos;Completed 1 of 1 items&apos;</span>
</code></pre>
<p>&#x5728;<a href="https://mobxjs.github.io/mobx/getting-started.html" target="_blank">10&#x5206;&#x949F;&#x5165;&#x95E8; MobX &#x548C; React</a>&#x4E2D;&#x4F60;&#x53EF;&#x4EE5;&#x6DF1;&#x5165;&#x672C;&#x793A;&#x4F8B;&#x5E76;&#x4E14;&#x56F4;&#x7ED5;&#x5B83;&#x4F7F;&#x7528; <a href="https://facebook.github.io/react/" target="_blank">React</a> &#x6765;&#x6784;&#x5EFA;&#x7528;&#x6237;&#x9875;&#x9762;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="overview.html" class="navigation navigation-prev " aria-label="Previous page: 1.1. MobX 要点">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../refguide/api.html" class="navigation navigation-next " aria-label="Next page: 2. API概览">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"1.2. 概念与原则","level":"1.1.2","depth":2,"next":{"title":"2. API概览","level":"1.2","depth":1,"path":"refguide/api.md","ref":"refguide/api.md","articles":[]},"previous":{"title":"1.1. MobX 要点","level":"1.1.1","depth":2,"path":"intro/overview.md","ref":"intro/overview.md","articles":[]},"dir":"ltr"},"config":{"plugins":["github","edit-link","anchors","copy-code-button","github-buttons"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"github":{"url":"https://github.com/SangKa/mobx-docs-cn"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"github-buttons":{"buttons":[{"user":"SangKa","repo":"MobX-Docs-CN","type":"star","size":"small","count":true},{"user":"SangKa","repo":"MobX-Docs-CN","type":"fork","size":"small","count":true}]},"copy-code-button":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"edit-link":{"label":"完善文档","base":"https://github.com/SangKa/mobx-docs-cn/tree/master/docs"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"anchors":{}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"MobX 中文文档","gitbook":"3.2.2"},"file":{"path":"intro/concepts.md","mtime":"2018-09-18T13:06:39.942Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2018-09-18T13:06:52.064Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-edit-link/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

